<template>
  <div class="admin-feedback">
    <!-- 猫咪动画区域 -->
    <div class="cat-animation-container">
      <div class="interactive-cat">
        <div class="cat-head">
          <div class="cat-ears">
            <div class="cat-ear left"></div>
            <div class="cat-ear right"></div>
          </div>
          <div class="cat-face">
            <div class="cat-eyes">
              <div class="cat-eye left"></div>
              <div class="cat-eye right"></div>
            </div>
            <div class="cat-nose"></div>
            <div class="cat-mouth"></div>
          </div>
        </div>
        <div class="cat-body">
          <div class="cat-tail"></div>
          <div class="cat-paws">
            <div class="cat-paw left-front"></div>
            <div class="cat-paw right-front"></div>
            <div class="cat-paw left-back"></div>
            <div class="cat-paw right-back"></div>
          </div>
        </div>
      </div>
      <div class="message-bubble">
        <span>欢迎来到反馈管理页面！我正在仔细查看每一条用户的心声~</span>
        <div class="bubble-icon">💌</div>
      </div>
      <div class="feedback-piles">
        <div class="feedback-paper"></div>
        <div class="feedback-paper"></div>
        <div class="feedback-paper"></div>
      </div>
    </div>
    
    <!-- 工具栏 -->
    <div class="toolbar">
      <div class="search-filter">
        <input 
          type="text" 
          v-model="searchQuery" 
          class="admin-form-input" 
          placeholder="搜索反馈内容或用户名..."
        />
        <select v-model="statusFilter" class="admin-form-input">
          <option value="all">所有状态</option>
          <option value="pending">待处理</option>
          <option value="processing">处理中</option>
          <option value="resolved">已解决</option>
          <option value="closed">已关闭</option>
        </select>
        <select v-model="typeFilter" class="admin-form-input">
          <option value="all">所有类型</option>
          <option value="bug">Bug反馈</option>
          <option value="feature">功能建议</option>
          <option value="complaint">投诉</option>
          <option value="question">问题咨询</option>
          <option value="other">其他</option>
        </select>
      </div>
      <div class="actions">
        <button class="admin-btn" @click="exportData">
          导出数据
        </button>
      </div>
    </div>

    <!-- 表格区域 -->
    <div class="table-container">
      <table class="admin-table">
        <thead>
          <tr>
            <th>ID</th>
            <th>用户名</th>
            <th>反馈类型</th>
            <th>标题</th>
            <th>提交时间</th>
            <th>状态</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="feedback in filteredFeedbacks" :key="feedback.id">
            <td>{{ feedback.id }}</td>
            <td>{{ feedback.username }}</td>
            <td>
              <span :class="getTypeClass(feedback.type)">
                {{ getTypeName(feedback.type) }}
              </span>
            </td>
            <td class="feedback-title">{{ feedback.title }}</td>
            <td>{{ feedback.createdAt }}</td>
            <td>
              <span :class="getStatusClass(feedback.status)">
                {{ getStatusName(feedback.status) }}
              </span>
            </td>
            <td class="actions-cell">
              <router-link :to="`/admin/feedback/${feedback.id}`" class="action-btn">
                查看
              </router-link>
              <button 
                v-if="feedback.status === 'pending'"
                class="action-btn" 
                @click="changeStatus(feedback, 'processing')"
              >
                处理
              </button>
              <button 
                v-if="feedback.status === 'processing'"
                class="action-btn" 
                @click="changeStatus(feedback, 'resolved')"
              >
                标记解决
              </button>
              <button 
                v-if="['pending', 'processing'].includes(feedback.status)"
                class="action-btn" 
                @click="changeStatus(feedback, 'closed')"
              >
                关闭
              </button>
            </td>
          </tr>
          <tr v-if="filteredFeedbacks.length === 0">
            <td colspan="7" class="empty-data">没有找到符合条件的反馈</td>
          </tr>
        </tbody>
      </table>
    </div>

    <!-- 分页区域 -->
    <div class="pagination" v-if="totalPages > 1">
      <button 
        class="page-btn" 
        :disabled="currentPage === 1"
        @click="goToPage(currentPage - 1)"
      >
        上一页
      </button>
      <div class="page-info">
        {{ currentPage }} / {{ totalPages }} 页 (共 {{ filteredFeedbacks.length }} 条)
      </div>
      <button 
        class="page-btn" 
        :disabled="currentPage === totalPages"
        @click="goToPage(currentPage + 1)"
      >
        下一页
      </button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'AdminFeedback',
  data() {
    return {
      feedbacks: [
        {
          id: 1,
          username: 'user123',
          type: 'bug',
          title: '无法完成每日低碳打卡任务',
          content: '我尝试提交每日低碳打卡任务，但系统显示"提交失败"，已经尝试多次。',
          createdAt: '2023-05-18 15:30',
          status: 'pending',
          email: 'user123@example.com',
          phone: '13800138000'
        },
        {
          id: 2,
          username: 'greenlife',
          type: 'feature',
          title: '建议增加团队挑战功能',
          content: '希望能增加团队挑战功能，让朋友们一起参与环保活动，相互鼓励。',
          createdAt: '2023-05-17 10:15',
          status: 'processing',
          email: 'greenlife@example.com',
          phone: null
        },
        {
          id: 3,
          username: 'ecofriend',
          type: 'question',
          title: '如何查看我的碳足迹历史记录？',
          content: '我想查看过去几个月的碳足迹记录，但找不到查询历史数据的入口。',
          createdAt: '2023-05-16 14:40',
          status: 'resolved',
          email: 'ecofriend@example.com',
          phone: '13900139000'
        },
        {
          id: 4,
          username: 'user456',
          type: 'complaint',
          title: '积分兑换商品长时间未发货',
          content: '我在5月10日兑换了一个环保杯，但至今未收到发货通知，已经过去一周了。',
          createdAt: '2023-05-15 09:20',
          status: 'closed',
          email: 'user456@example.com',
          phone: '13700137000'
        },
        {
          id: 5,
          username: 'carbonsaver',
          type: 'other',
          title: '希望与平台进行商务合作',
          content: '我们是一家环保产品公司，希望能与平台合作，将我们的产品加入到积分商城中。',
          createdAt: '2023-05-14 16:50',
          status: 'pending',
          email: 'business@carbonsaver.com',
          phone: '18600186000'
        }
      ],
      searchQuery: '',
      statusFilter: 'all',
      typeFilter: 'all',
      currentPage: 1,
      pageSize: 10
    }
  },
  computed: {
    filteredFeedbacks() {
      return this.feedbacks.filter(feedback => {
        // 搜索过滤
        const matchesSearch = 
          (feedback.title && feedback.title.toLowerCase().includes(this.searchQuery.toLowerCase())) ||
          (feedback.content && feedback.content.toLowerCase().includes(this.searchQuery.toLowerCase())) ||
          (feedback.username && feedback.username.toLowerCase().includes(this.searchQuery.toLowerCase()));
        
        // 状态过滤
        const matchesStatus = this.statusFilter === 'all' || feedback.status === this.statusFilter;
        
        // 类型过滤
        const matchesType = this.typeFilter === 'all' || feedback.type === this.typeFilter;
        
        return matchesSearch && matchesStatus && matchesType;
      });
    },
    displayedFeedbacks() {
      const startIndex = (this.currentPage - 1) * this.pageSize;
      const endIndex = startIndex + this.pageSize;
      return this.filteredFeedbacks.slice(startIndex, endIndex);
    },
    totalPages() {
      return Math.ceil(this.filteredFeedbacks.length / this.pageSize);
    }
  },
  methods: {
    getTypeName(type) {
      const typeMap = {
        'bug': 'Bug反馈',
        'feature': '功能建议',
        'complaint': '投诉',
        'question': '问题咨询',
        'other': '其他'
      };
      return typeMap[type] || '未知类型';
    },
    getTypeClass(type) {
      const classMap = {
        'bug': 'admin-tag admin-tag-red',
        'feature': 'admin-tag admin-tag-blue',
        'complaint': 'admin-tag admin-tag-orange',
        'question': 'admin-tag admin-tag-green',
        'other': 'admin-tag'
      };
      return classMap[type] || 'admin-tag';
    },
    getStatusName(status) {
      const statusMap = {
        'pending': '待处理',
        'processing': '处理中',
        'resolved': '已解决',
        'closed': '已关闭'
      };
      return statusMap[status] || '未知状态';
    },
    getStatusClass(status) {
      const classMap = {
        'pending': 'admin-tag admin-tag-orange',
        'processing': 'admin-tag admin-tag-blue',
        'resolved': 'admin-tag admin-tag-green',
        'closed': 'admin-tag admin-tag-red'
      };
      return classMap[status] || 'admin-tag';
    },
    changeStatus(feedback, newStatus) {
      feedback.status = newStatus;
    },
    goToPage(page) {
      if (page >= 1 && page <= this.totalPages) {
        this.currentPage = page;
      }
    },
    exportData() {
      alert('导出反馈数据功能将在后续版本中实现');
    }
  }
}
</script>

<style scoped>
.admin-feedback {
  width: 100%;
  padding: 0;
}

/* 猫咪动画容器 */
.cat-animation-container {
  position: relative;
  height: 180px;
  margin: 0;
  padding: 20px;
  background-color: #fff8f6;
  border-radius: 0;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.05);
  overflow: hidden;
}

.interactive-cat {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-80px);
  width: 80px;
  height: 70px;
  z-index: 5;
}

.cat-head {
  position: relative;
  width: 50px;
  height: 45px;
  background-color: #e9967a;
  border-radius: 50%;
  z-index: 2;
}

.cat-ears {
  position: absolute;
  top: -10px;
  width: 100%;
}

.cat-ear {
  position: absolute;
  width: 0;
  height: 0;
  border-bottom: 20px solid #e9967a;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
}

.cat-ear.left {
  left: 0;
  transform: rotate(-30deg);
}

.cat-ear.right {
  right: 0;
  transform: rotate(30deg);
}

.cat-face {
  position: relative;
  padding-top: 10px;
}

.cat-eyes {
  display: flex;
  justify-content: space-around;
  margin-bottom: 5px;
}

.cat-eye {
  width: 8px;
  height: 12px;
  background-color: #000;
  border-radius: 50%;
  animation: blink 4s infinite;
}

@keyframes blink {
  0%, 96%, 100% { transform: scaleY(1); }
  98% { transform: scaleY(0.1); }
}

.cat-nose {
  width: 8px;
  height: 5px;
  background-color: #ff9999;
  border-radius: 50%;
  margin: 3px auto;
}

.cat-mouth {
  width: 10px;
  height: 5px;
  border-bottom: 2px solid #333;
  border-radius: 50%;
  margin: 2px auto;
  animation: mouth-move 5s infinite;
}

@keyframes mouth-move {
  0%, 20%, 40%, 60%, 80%, 100% { transform: scaleY(1); }
  10%, 30%, 50%, 70%, 90% { transform: scaleY(1.2); }
}

.cat-body {
  position: relative;
  top: -15px;
  width: 60px;
  height: 40px;
  background-color: #e9967a;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
}

.cat-tail {
  position: absolute;
  right: -20px;
  bottom: 15px;
  width: 40px;
  height: 10px;
  background-color: #e9967a;
  border-radius: 0 5px 5px 0;
  transform-origin: 0 50%;
  animation: tail-wag 3s infinite ease-in-out;
}

@keyframes tail-wag {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(20deg); }
}

.cat-paws {
  position: absolute;
  bottom: -8px;
  width: 100%;
}

.cat-paw {
  position: absolute;
  width: 12px;
  height: 10px;
  background-color: #f4a460;
  border-radius: 50%;
}

.cat-paw.left-front {
  left: 10px;
  animation: paw-tap 1.5s infinite alternate;
}

.cat-paw.right-front {
  left: 40px;
}

@keyframes paw-tap {
  0% { transform: translateY(0); }
  100% { transform: translateY(-3px); }
}

.message-bubble {
  position: absolute;
  top: 20px;
  left: 150px;
  background-color: white;
  padding: 10px 15px;
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 350px;
  z-index: 10;
}

.message-bubble:before {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 20px;
  border-top: 10px solid white;
  border-right: 10px solid transparent;
  border-left: 10px solid transparent;
}

.bubble-icon {
  font-size: 18px;
  animation: bounce 2s infinite;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

.feedback-piles {
  position: absolute;
  bottom: 30px;
  right: 100px;
  z-index: 1;
}

.feedback-paper {
  position: absolute;
  width: 40px;
  height: 50px;
  background-color: white;
  border: 1px solid #e0e0e0;
  transform: rotate(5deg);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.feedback-paper:nth-child(2) {
  top: 5px;
  left: 10px;
  transform: rotate(-3deg);
}

.feedback-paper:nth-child(3) {
  top: 10px;
  left: 5px;
  transform: rotate(2deg);
}

/* 工具栏样式 */
.toolbar {
  display: flex;
  justify-content: space-between;
  margin: 16px 24px;
  gap: 10px;
}

.search-filter {
  display: flex;
  gap: 10px;
  flex: 1;
}

.actions {
  display: flex;
  gap: 10px;
}

/* 表格容器样式 */
.table-container {
  width: 100%;
  overflow-x: auto;
  padding: 0 24px;
}

.feedback-title {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions-cell {
  display: flex;
  gap: 8px;
}

.action-btn {
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  background-color: transparent;
  color: #1890ff;
  border: none;
  transition: all 0.3s;
}

.action-btn:hover {
  background-color: rgba(24, 144, 255, 0.1);
}

.empty-data {
  text-align: center;
  padding: 30px 0;
  color: #999;
}

/* 分页样式 */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 16px 24px;
  gap: 10px;
}

.page-btn {
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid #d9d9d9;
  background-color: white;
  transition: all 0.3s;
}

.page-btn:disabled {
  cursor: not-allowed;
  color: rgba(0, 0, 0, 0.25);
  background-color: #f5f5f5;
  border-color: #d9d9d9;
}

.page-btn:not(:disabled):hover {
  color: #40a9ff;
  border-color: #40a9ff;
}

.page-info {
  color: rgba(0, 0, 0, 0.65);
}

/* 响应式调整 */
@media (max-width: 768px) {
  .toolbar {
    flex-direction: column;
  }
  
  .search-filter {
    flex-direction: column;
    width: 100%;
  }
  
  .actions {
    width: 100%;
  }
  
  .cat-animation-container {
    height: 220px;
  }
  
  .message-bubble {
    top: 110px;
    left: 20px;
    right: 20px;
    max-width: none;
  }
}
</style> 